﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace CommonUtils
{
    public class FilterOfAction : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " start FilterOfAction: "
        + context.HttpContext.Request.Path).Print();
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " end FilterOfAction: "
        + context.HttpContext.Request.Path).Print();
        }

        public static void AddTo(IServiceCollection services)
        {
            services.AddMvc(options => options.Filters.Add<FilterOfAction>());
        }
    }
}
